/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */
package cn.com.ksplatform.modules.autocode.manager.service;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import org.springframework.stereotype.Component;

import cn.com.ksplatform.base.service.BaseService;
import cn.com.ksplatform.modules.autocode.manager.model.Module;
import cn.com.ksplatform.modules.autocode.util.XmlUtil;

/**
 * ClassName:ModuleService.java <br/>
 * Date: 2015年11月4日 <br/>
 * 
 * @author Mr.Xiao
 * @version 1.0
 */
@Component("modules.autocode.ModuleService")
public class ModuleService extends BaseService{
	
	/**
	 * 创建模块
	 * @param module
	 * @return
	 * @throws FileNotFoundException 
	 */
	public void saveModule(Module module) throws Exception {
		File f = new File(module.getProject().getBulidPath()+File.separator+module.getModulesCode()+File.separator+"module.xml");
		if(f.exists()){
			throw new Exception("模块已存在");
		}else{
			f.getParentFile().mkdir();
		}
		FileOutputStream ous = new FileOutputStream(f);
		module.setProject(null);
		XmlUtil.saveObject2Xml(module, ous);
	}

}
